/******************************************************************************* 
 *  Copyright 2007 Amazon Technologies, Inc.  
 *  Licensed under the Apache License, Version 2.0 (the "License"); 
 *  
 *  You may not use this file except in compliance with the License. 
 *  You may obtain a copy of the License at: http://aws.amazon.com/apache2.0
 *  This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 
 *  CONDITIONS OF ANY KIND, either express or implied. See the License for the 
 *  specific language governing permissions and limitations under the License.
 * ***************************************************************************** 
 *    __  _    _  ___ 
 *   (  )( \/\/ )/ __)
 *   /__\ \    / \__ \
 *  (_)(_) \/\/  (___/
 * 
 *  Amazon ECS CSharp Library
 *  API Version: 2007-07-16
 *  Generated: Thu Aug 02 10:15:38 PDT 2007 
 * 
 */

using System;
using System.Xml.Serialization;
using System.Collections.Generic;
using Amazon.ECS;
using Amazon.ECS.Model;

namespace Amazon.ECS.Samples
{

    /// <summary>
    /// Browse Node Lookup  Samples
    /// </summary>
    public class BrowseNodeLookupSample
    {
    
                                     
        /// <summary>
        /// 
        /// <p/>
        /// Given a browse node ID, BrowseNodeLookup returns the specified browse node's name, children, and ancestors.
        /// The names and browse node IDs of the children and ancestor browse nodes are also returned.
        /// BrowseNodeLookup enables you to traverse the browse node hierarchy to find a browse node.
        /// As you traverse down the hierarchy, you refine your search and limit the number of items returned.
        /// For example, you might traverse the following hierarchy: DVD Used DVDs Kids and Family,
        /// to select out of all the DVDs offered by Amazon only those that are appropriate for family viewing.
        /// Returning the items associated with Kids and Family produces a much more targeted result than a search
        /// based at the level of Used DVDs.
        /// <p/>
        /// Alternatively, by traversing up the browse node tree, you can determine the root category of an item.
        /// You might do that, for example, to return the top seller of the root product category using the
        /// TopSeller response group in an ItemSearch request.
        /// <p/>
        /// You can use BrowseNodeLookup iteratively to navigate through the browse node hierarchy to
        /// reach the node that most appropriately suits your search. Then you can use the browse node ID in
        /// an ItemSearch request. This response would be far more targeted than, for example,
        /// searching through all of the browse nodes in a search index.
        /// <p/>
        /// <b>Available Response Groups</b>:
        /// <ul>
        /// <li>Request</li>
        /// <li>BrowseNodeInfo</li>
        /// </ul>
        /// 
        /// </summary>
        /// <param name="service">Instance of AmazonECS service</param>
        /// <param name="request">BrowseNodeLookup request</param>
        public static void InvokeBrowseNodeLookup(AmazonECS service, params BrowseNodeLookupRequest [] request) 
        {
            try 
            {
                BrowseNodeLookupResponse response = service.BrowseNodeLookup(request);
                
                
                Console.WriteLine ("Service Response");
                Console.WriteLine ("=============================================================================");
                Console.WriteLine ();

                Console.WriteLine("        BrowseNodeLookupResponse");
                if (response.IsSetOperationRequest()) 
                {
                    Console.WriteLine("            OperationRequest");
                    OperationRequest  operationRequest = response.OperationRequest;
                    if (operationRequest.IsSetHTTPHeaders()) 
                    {
                        Console.WriteLine("                HTTPHeaders");
                        HTTPHeaders  HTTPHeaders = operationRequest.HTTPHeaders;
                    } 
                    if (operationRequest.IsSetRequestId()) 
                    {
                        Console.WriteLine("                RequestId");
                        Console.WriteLine("                    {0}", operationRequest.RequestId);
                    }
                    if (operationRequest.IsSetArguments()) 
                    {
                        Console.WriteLine("                Arguments");
                        Arguments  arguments = operationRequest.Arguments;
                    } 
                    if (operationRequest.IsSetRequestProcessingTime()) 
                    {
                        Console.WriteLine("                RequestProcessingTime");
                        Console.WriteLine("                    {0}", operationRequest.RequestProcessingTime);
                    }
                } 
                List<BrowseNodes> browseNodesList = response.BrowseNodes;
                foreach (BrowseNodes browseNodes in browseNodesList) 
                {
                    Console.WriteLine("            BrowseNodes");
                    List<BrowseNode> browseNodeList = browseNodes.BrowseNode;
                    foreach (BrowseNode browseNode in browseNodeList) 
                    {
                        Console.WriteLine("                BrowseNode");
                        if (browseNode.IsSetBrowseNodeId()) 
                        {
                            Console.WriteLine("                    BrowseNodeId");
                            Console.WriteLine("                        {0}", browseNode.BrowseNodeId);
                        }
                        if (browseNode.IsSetName()) 
                        {
                            Console.WriteLine("                    Name");
                            Console.WriteLine("                        {0}", browseNode.Name);
                        }
                        if (browseNode.IsSetIsCategoryRoot()) 
                        {
                            Console.WriteLine("                    IsCategoryRoot");
                            Console.WriteLine("                        {0}", browseNode.IsCategoryRoot);
                        }
                        if (browseNode.IsSetProperties()) 
                        {
                            Console.WriteLine("                    Properties");
                            BrowseNodeProperties  properties = browseNode.Properties;
                            List<Property> propertyList = properties.Property;
                            foreach (Property property in propertyList) 
                            {
                                Console.WriteLine("                        Property");
                                if (property.IsSetName()) 
                                {
                                    Console.WriteLine("                            Name");
                                    Console.WriteLine("                                {0}", property.Name);
                                }
                                if (property.IsSetValue()) 
                                {
                                    Console.WriteLine("                            Value");
                                    Console.WriteLine("                                {0}", property.Value);
                                }
                            }
                        } 
                        if (browseNode.IsSetChildren()) 
                        {
                            Console.WriteLine("                    Children");
                            BrowseNodeChildren  children = browseNode.Children;
                        } 
                        if (browseNode.IsSetAncestors()) 
                        {
                            Console.WriteLine("                    Ancestors");
                            BrowseNodeAncestors  ancestors = browseNode.Ancestors;
                        } 
                        if (browseNode.IsSetTopSellers()) 
                        {
                            Console.WriteLine("                    TopSellers");
                            TopSellers  topSellers = browseNode.TopSellers;
                            List<TopSeller> topSellerList = topSellers.TopSeller;
                            foreach (TopSeller topSeller in topSellerList) 
                            {
                                Console.WriteLine("                        TopSeller");
                                if (topSeller.IsSetASIN()) 
                                {
                                    Console.WriteLine("                            ASIN");
                                    Console.WriteLine("                                {0}", topSeller.ASIN);
                                }
                                if (topSeller.IsSetTitle()) 
                                {
                                    Console.WriteLine("                            Title");
                                    Console.WriteLine("                                {0}", topSeller.Title);
                                }
                            }
                        } 
                        if (browseNode.IsSetNewReleases()) 
                        {
                            Console.WriteLine("                    NewReleases");
                            NewReleases  newReleases = browseNode.NewReleases;
                            List<NewRelease> newReleaseList = newReleases.NewRelease;
                            foreach (NewRelease newRelease in newReleaseList) 
                            {
                                Console.WriteLine("                        NewRelease");
                                if (newRelease.IsSetASIN()) 
                                {
                                    Console.WriteLine("                            ASIN");
                                    Console.WriteLine("                                {0}", newRelease.ASIN);
                                }
                                if (newRelease.IsSetTitle()) 
                                {
                                    Console.WriteLine("                            Title");
                                    Console.WriteLine("                                {0}", newRelease.Title);
                                }
                            }
                        } 
                    }
                }

            } 
            catch (AmazonECSException ex) 
            {
                Console.WriteLine("Caught Exception: " + ex.Message);
                Console.WriteLine("Response Status Code: " + ex.StatusCode);
                Console.WriteLine("Error Code: " + ex.ErrorCode);
                Console.WriteLine("Request ID: " + ex.RequestId);
                Console.WriteLine("XML: " + ex.XML);
            }
        }
                                                                    }
}
